import { Injectable } from '@angular/core'
import { HttpClient, HttpParams } from '@angular/common/http'
import { Observable } from 'rxjs'

import { COMB_URL } from 'app/utils/contraints'
import { IAamsPagination, IAamsQuery } from './aams-select.interface'

@Injectable()
export class AamsSelectService {
  constructor(private http: HttpClient) {}

  query(params: IAamsQuery): Observable<IAamsPagination> {
    let p = new HttpParams()
    Object.keys(params).filter(k => !!params[k]).forEach(key => {
      p = p.append(key, params[key])
    })
    const url = `${COMB_URL}/camel/biz/list`

    return this.http.get<IAamsPagination>(url, {
      params: p,
    })
  }
}
